package com.bbs.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bbs.service.ModeratorService;

public class ModeratorServlet extends HttpServlet {


	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String method = request.getParameter("_method");
		if("resetmoderator".equals(method)){
			resetModerator(request,response);
		} else {
			response.sendError(404);
		}
	}

	private void resetModerator(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		String uid = request.getParameter("userid");
		String bid = request.getParameter("blocks");
		new ModeratorService().delete(Integer.parseInt(uid),Integer.parseInt(bid));
		response.sendRedirect("user.jspx?_method=showusers");
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
